package com.tjetc.service.impl;

import com.tjetc.entity.SecondKills;
import com.tjetc.dao.SecondKillsDao;
import com.tjetc.entity.ShoePhotos;
import com.tjetc.service.SecondKillsService;
import com.tjetc.util.Pager;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 秒杀表(SecondKills)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:06:07
 */
@Service("secondKillsService")
public class SecondKillsServiceImpl implements SecondKillsService {
    @Resource
    private SecondKillsDao secondKillsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param skid 主键
     * @return 实例对象
     */
    @Override
    public SecondKills queryById(Long skid) {
        return this.secondKillsDao.queryById(skid);
    }

    /**
     * 分页查询
     *
     * @param secondKills 筛选条件
    分页对象
     * @return 查询结果
     */
    @Override
    public Object queryByPage(SecondKills secondKills, Integer pageNum,Integer pageSize) {
        //查询总记录条数
        Integer recordCount = secondKillsDao.count(secondKills);
        //构建分页信息对象
        Pager pager = new Pager(pageNum, pageSize, recordCount);
        //根据pager查询需要的数据
        List<SecondKills> list = secondKillsDao.queryAllByLimit(secondKills,pager.getStart(), pageSize);
        //将分页信息和查询到的数据一起返回到前端
        HashMap<String,Object> map = new HashMap<>();
        map.put("pager",pager);
        map.put("list",list);
        return map;
    }

    /**
     * 新增数据
     *
     * @param secondKills 实例对象
     * @return 实例对象
     */
    @Override
    public SecondKills insert(SecondKills secondKills) {
        this.secondKillsDao.insert(secondKills);
        return secondKills;
    }

    /**
     * 修改数据
     *
     * @param secondKills 实例对象
     * @return 实例对象
     */
    @Override
    public SecondKills update(SecondKills secondKills) {
        this.secondKillsDao.update(secondKills);
        return this.queryById(secondKills.getSkid());
    }

    /**
     * 通过主键删除数据
     *
     * @param skid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long skid) {
        return this.secondKillsDao.deleteById(skid) > 0;
    }
}
